package com.ruoyi.wms.controller.partolStore;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.idempotent.annotation.RepeatSubmit;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.web.core.BaseController;
import com.ruoyi.common.mybatis.core.page.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.excel.utils.ExcelUtil;
import com.ruoyi.wms.domain.vo.RepairRecordsVo;
import com.ruoyi.wms.domain.bo.partolStore.RepairRecordsBo;
import com.ruoyi.wms.service.RepairRecordsService;
import com.ruoyi.common.mybatis.core.page.TableDataInfo;

/**
 * 维修记录
 *
 * @author xhr
 * @date 2024-12-04
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/wms/repairRecords")
public class RepairRecordsController extends BaseController {

    private final RepairRecordsService repairRecordsService;

    /**
     * 查询维修记录列表
     */
    @SaCheckPermission("wms:repairRecords:list")
    @GetMapping("/list")
    public TableDataInfo<RepairRecordsVo> list(RepairRecordsBo bo, PageQuery pageQuery) {
        return repairRecordsService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出维修记录列表
     */
    @SaCheckPermission("wms:repairRecords:export")
    @Log(title = "维修记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(RepairRecordsBo bo, HttpServletResponse response) {
        List<RepairRecordsVo> list = repairRecordsService.queryList(bo);
        ExcelUtil.exportExcel(list, "维修记录", RepairRecordsVo.class, response);
    }

    /**
     * 获取维修记录详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("wms:repairRecords:query")
    @GetMapping("/{id}")
    public R<RepairRecordsVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(repairRecordsService.queryById(id));
    }

    /**
     * 新增维修记录
     */
    @SaCheckPermission("wms:repairRecords:add")
    @Log(title = "维修记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody RepairRecordsBo bo) {
        repairRecordsService.insertByBo(bo);
        return R.ok();
    }

    /**
     * 修改维修记录
     */
    @SaCheckPermission("wms:repairRecords:edit")
    @Log(title = "维修记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody RepairRecordsBo bo) {
        repairRecordsService.updateByBo(bo);
        return R.ok();
    }

    /**
     * 删除维修记录
     *
     * @param ids 主键串
     */
    @SaCheckPermission("wms:repairRecords:remove")
    @Log(title = "维修记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        repairRecordsService.deleteByIds(List.of(ids));
        return R.ok();
    }
}
